//
//  TabbarView.m
//  TGQ2
//
//  Created by 元元 on 14-7-16.
//  Copyright (c) 2014年 元元. All rights reserved.
//

#import "TabbarView.h"
#define widthRate [UIScreen mainScreen].applicationFrame.size.width/320.0f
@implementation TabbarView
@synthesize tabimage;
@synthesize tablab;
@synthesize delegate;

-(void)dealloc
{
    delegate=nil;
}


- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        
        tabimage=[[UIImageView alloc] init];
        tabimage.frame=CGRectMake( 29*widthRate, 6, 22, 22);
        tabimage.contentMode=UIViewContentModeScaleToFill;
        [self addSubview:tabimage];
        
        tablab=[[UILabel alloc]initWithFrame:CGRectMake(0, 30, 80*widthRate, 17)];
        tablab.backgroundColor=[UIColor clearColor];//字的背景底色
        tablab.textAlignment=NSTextAlignmentCenter;
        tablab.font=[UIFont systemFontOfSize:11];
        tablab.textColor=[UIColor grayColor];
        [self addSubview:tablab];
   
        UIButton *tabbtn=[UIButton buttonWithType:UIButtonTypeCustom];
        tabbtn.frame=CGRectMake(0, 0, 64*widthRate, 49);
        tabbtn.backgroundColor = [UIColor clearColor];
        
        [tabbtn addTarget:self action:@selector(TabbarViewBtnPressed:) forControlEvents:UIControlEventTouchDown];
        [self addSubview:tabbtn];
    }
    return self;
}

-(void)TabbarViewBtnPressed:(id)sender
{
    [delegate TabbarViewDelegateBtnPressed:(int)(self.tag)];
}

-(void)setselect:(BOOL)bol
{
    switch (self.tag) {
        case 1:
        {
            tabimage.image=[UIImage imageNamed:bol? @"d_icon2_65.png":@"d_icon_65.png"];
            tablab.text=@"首页";
            tablab.textColor=bol? [UIColor orangeColor]:[UIColor grayColor];
        }
            break;
        case 2:
        {
            tabimage.image=[UIImage imageNamed:bol? @"d_icon2_62.png":@"d_icon_62.png"];
            tablab.text=@"消息";
            tablab.textColor=bol? [UIColor orangeColor]:[UIColor grayColor];
        }
            break;
        case 3:
        {
            tabimage.image=[UIImage imageNamed:bol? @"d_icon2_83.png":@"d_icon_83.png"];
            tablab.text=@"公告";
            tablab.textColor=bol? [UIColor orangeColor]:[UIColor grayColor];
        }
            break;
        case 4:
        {
            tabimage.image=[UIImage imageNamed:bol? @"d_icon2_71.png":@"d_icon_71.png"];
            tablab.text=@"推荐";
            tablab.textColor=bol? [UIColor orangeColor]:[UIColor grayColor];
        }
            break;
        case 5:
        {
            tabimage.image = [UIImage imageNamed:bol?@"d_icon2_74.png":@"d_icon_74.png"];
            tablab.text=@"我的";
            tablab.textColor=bol? [UIColor orangeColor]:[UIColor grayColor];
        }
        default:
            break;
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
